package com.zlsy.learning.leetcode.linkedlist.l234;

/**
 * @author zhouliang
 * @date 2020/8/3 14:00
 */
public class ListNode {
  /** 存放当前node数据的变量值 */
  public int val;
  /** 存放下一个node的变量信息 */
  public ListNode next;

  public ListNode() {}

  public ListNode(int val) {
    this.val = val;
  }

  /**
   * 添加节点
   *
   * @param newdata
   */
  public void add(int newdata) {
    // 创建一个结点
    ListNode newNode = new ListNode(newdata);
    if (this.next == null) {
      this.next = newNode;
    } else {
      this.next.add(newdata);
    }
  }

  public void print() {
    System.out.println(this.val + "-->");
    if (this.next != null) {
      this.next.print();
    }
  }
}
